/**
 * 
 */
package org.azdroid.kit.net;

/**
 * 数据请求抽象数据类
 * 
 * @author hljdrl@gmail.com
 * 
 */
public abstract class Packet {
	/**
	 * 
	 * Packet类型
	 * 
	 * @author hljdrl@gmail.com
	 * 
	 */
	public static class Type {

		public static final Type GET = new Type("get");
		public static final Type SET = new Type("set");
		public static final Type RESULT = new Type("result");
		public static final Type ERROR = new Type("error");

		/**
		 * Converts a String into the corresponding types. Valid String values
		 * that can be converted to types are: "get", "set", "result", and
		 * "error".
		 * 
		 * @param type
		 *            the String value to covert.
		 * @return the corresponding Type.
		 */
		public static Type fromString(String type) {
			if (type == null) {
				return null;
			}
			type = type.toLowerCase();
			if (GET.toString().equals(type)) {
				return GET;
			} else if (SET.toString().equals(type)) {
				return SET;
			} else if (ERROR.toString().equals(type)) {
				return ERROR;
			} else if (RESULT.toString().equals(type)) {
				return RESULT;
			} else {
				return null;
			}
		}

		private String value;

		private Type(String value) {
			this.value = value;
		}

		public String toString() {
			return value;
		}
	}

	protected int mTaskId;
	private Type type;

	public Packet(int taskId) {
		this.mTaskId = taskId;
	}

	public int getTaskId() {
		return mTaskId;
	}

	public void setTaskId(int id) {
		mTaskId = id;
	}

	public Type getType() {
		return type;
	}

	public void setType(Type type) {
		this.type = type;
	}
}
